package com.renge.eduservice.controller;


import com.renge.commonutils.R;
import com.renge.eduservice.entity.EduVideo;
import com.renge.eduservice.service.EduVideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-06-04
 */
@Api(description="小节管理")
@RestController
@RequestMapping("/eduservice/edu-video")
@CrossOrigin
public class EduVideoController {
     @Autowired
      private EduVideoService eduVideoService;

      @ApiOperation(value = "根据id查询小节")
      @GetMapping("{id}")
      public R getEduVideoById(@ApiParam(name = "id",value = "小节id",required = true)
                             @PathVariable("id")String id){
          EduVideo byId = eduVideoService.getById(id);
          if(byId==null){
              return R.error();
          }
          return R.ok().data("eduVideo",byId);
      }
    @ApiOperation(value = "将EduVideo保存或者修改表中")
    @PostMapping("/save")
    public R saveOrupdateEduVideo(@ApiParam(name = "eduVideo",value = "小节",required = true)
                             @RequestBody EduVideo eduVideo){
        boolean b = eduVideoService.saveOrUpdate(eduVideo);
        if(!b){
            return R.error();
        }
        return R.ok();
    }
    @ApiOperation(value = "根据id删除EduVideo")
    @DeleteMapping("{id}")
    public R deleteEduVideoById(@ApiParam(name = "id",value = "小节id",required = true)
                                    @PathVariable("id")String id){
        boolean b = eduVideoService.deleteById(id);
        if(!b){
            return R.error();
        }
        return R.ok();
    }

}

